import { labelStyle } from './common.ts'
import { LightStyle } from '@tslsmart/charts/src/index.js'
export interface SunBurstItem {
  name: string
  value?: number
  code?: string
  children?: SunBurstItem[]
}
export const getOption = (data: SunBurstItem[], total: number) => {
  const style = new LightStyle()
  return {

    series: {
      type: 'sunburst',
      color: style.colors,
      data: data,
      radius: [0, '95%'],
      emphasis: {
        focus: 'ancestor'
      },
      label: {
        formatter(params: any) {

          const { name, value } = params

          const percent = (value / (total || 1) * 100).toFixed(2)
          if (+percent < 8) {
            return `${name} ${percent}% `
          } else {
            return `
  ${name}
  ${percent}% 
          `
          }

        },
      },

      levels: [
        {
          itemStyle: {
            color: '#fff'
          }
        },
        {
          radius: ['5%', '40%'],
          itemStyle: {
            borderWidth: 1
          },
          label: {
            ...labelStyle()
          }
        },
        {
          radius: ['40%', '70%'],
          itemStyle: {
            borderWidth: 1
          },
          label: {
            ...labelStyle()

          }
        },
        {
          radius: ['70%', '98%'],
          label: {
            ...labelStyle(),

          },
          itemStyle: {
            borderWidth: 0.5
          }
        },

      ]
    }
  }
}